package Socket;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class FileScoket {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8888);
        //创建客户端对象
        FileInputStream fis = new FileInputStream("C:\\Users\\啦啦啦\\Desktop\\学习周记.md");
        //创建文件读取对象
        OutputStream os = socket.getOutputStream();
        int len = 0;
        byte[] bytes = new byte[1024];
        while((len=fis.read(bytes))!=-1)
        {
            os.write(bytes,0,len);
            //将文件写入服务器中
        }
        InputStream is = socket.getInputStream();
        socket.shutdownOutput();
        //用这个上传一个结束标记
        while((len = is.read(bytes))!=-1)
        {
            System.out.println(new String (bytes,0,len));
            //使用InputStream对象中的read方法，读取服务器回写的数据
        }
        fis.close();
        socket.close();
    }
}
